#include <cmath>
#include <vector>
#include <iostream>
#include <vector>

#include <Windows.h>
#include <GL\GL.h>
#include <GL\GLU.h>

#include "utility.h"
#include "mesh.h"


//FIXME here the performance is bad.
void index2barycentric (unsigned res, unsigned idx, unsigned & x, unsigned & y)
{
	float m = (2.0f * res + 3); 
	x = int (0.5 * (m - sqrt (m*m - 8.0f * idx) )) ;
	y = idx - (res + 1 + res + 2 - x ) * x / 2 ;
}
/*
int barycentric2index (unsigned res,  unsigned i, unsigned j)
{
	return  (res + 1 + res + 2 - i ) * i / 2 + j; 
}
*/
float randreal()
{
	return (float(rand()% 32768)/float(32767));
}
int_RGB rand_color() 
{
	return int_RGB (rand () % 256, rand () % 256, rand () % 256) ;
}
/*
void drawsphere(float x, float y, float z, float radius) 
{
	glTranslatef(x ,y,z);
	//glutSolidSphere(radius,10,10);
	//Fix draw sphere here. 
	glTranslatef(- x , -y, -z);
}

*/